package org.gwtde.client.controllers;

import net.mygwt.ui.client.data.Model;
import net.mygwt.ui.client.mvc.AppEvent;
import net.mygwt.ui.client.mvc.Controller;

import org.gwtde.client.DesktopEvents;
import org.gwtde.client.model.AppLink;
import org.gwtde.client.model.Folder;
import org.gwtde.client.views.DockView;

public class DockController extends Controller {

	private DockView mDockView;

	public DockController() {
		registerEventType(DesktopEvents.Init);
		registerEventType(DesktopEvents.Resize);
		registerEventType(DesktopEvents.DockActivate);
		
		registerEventType(DesktopEvents.DockNavApps);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.mygwt.ui.client.mvc.Controller#handleEvent(net.mygwt.ui.client.mvc.AppEvent)
	 */
	public void handleEvent(AppEvent pEvent) {
		switch (pEvent.type) {
		case DesktopEvents.Init:
			forwardToView(mDockView, pEvent);
			break;
		case DesktopEvents.Resize:
			forwardToView(mDockView, pEvent);
			break;
		case DesktopEvents.DockActivate:
			forwardToView(mDockView, pEvent);
			break;
		case DesktopEvents.DockNavApps:
			forwardToView(mDockView, pEvent);
			break;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.mygwt.ui.client.mvc.Controller#initialize()
	 */
	public void initialize() {
		mDockView = new DockView(this, getModel());
	}

	private Model getModel() {
		Folder[] folders = new Folder[] {
				new Folder(
						"MyGWT Demos",
						new AppLink[] {
								new AppLink("MyGWTExplorer", "Explorer",
										"Explorer",
										"http://mygwt.net/deploy/mygwt-0.4.0/explorer/"),
								new AppLink("MyGWTMail", "Mail", "Mail",
										"http://mygwt.net/deploy/mygwt-0.4.0/mail/") }),
				new Folder("Google",
						new AppLink[] {
								new AppLink("GoogleSearch", "Google Search",
										"Search the Internet",
										"http://www.google.com/"),
								new AppLink("GoogleCalendar",
										"Google Calendar", "Internet Calendar",
										"http://www.google.com/calendar/"),
								new AppLink("GoogleNews", "Google News",
										"Be informed by Google News",
										"http://news.google.com/"),
								new AppLink("Blogger", "Blogger",
										"Create your Blog Now",
										"http://www.blogger.com/") }),
				new Folder("Entertainment", new AppLink[] { new AppLink(
						"iDesktopTV", "iDesktop.tv",
						"The slickest youtube browser yet",
						"http://www.idesktop.tv") }),
				new Folder("Education", new AppLink[] { new AppLink(
						"Wikipedia", "Wikipedia",
						"The free encyclopedia that anyone can edit",
						"http://www.wikipedia.org/") }) };
		Folder root = new Folder("root");
		for (int i = 0; i < folders.length; i++) {
			root.add((Folder) folders[i]);
		}
		return root;
	}

}
